package cn.tp.ksoft.civil_driver.request;

import okhttp3.Call;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import cn.tp.ksoft.library_civil.request.OkHttpUtils;
import cn.tp.ksoft.library_civil.request.builder.PostFormBuilder;
import cn.tp.ksoft.library_civil.request.callback.BitmapCallback;

/**
 *	基于okhttp的下载请求操作
 */
public class DownloadRequest extends BaseRequest{
	
	public DownloadRequest(Context context, Handler handler) {
		super(context, handler);
	}

	public void downloadImage(String url){
		PostFormBuilder builder = OkHttpUtils.post().url(url);
		builder.build().execute(new BitmapCallback() {
			
			@Override
			public void onResponse(Bitmap response) {
				Message message = Message.obtain();
				message.what = 0;
				message.obj = response;
				mHandler.sendMessage(message);
			}
			@Override
			public void onError(Call call, Exception e) {
			}
		});
	}
}
